<template>
    <div class="p-2">
        <el-card shadow="never">
            <template #header>
                <el-form :model="queryParams" ref="queryFormRef" :inline="true">
                    <el-form-item label="请选择客户：" prop="orderPrintStatus">
                        <el-select style="width: 100px;" v-model="queryParams.orderPrintStatus" clearable>
                            <el-option label="未打印" value="0"></el-option>
                            <el-option label="已打印" value="1"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="制单日期：" prop="timeDate">
                        <el-date-picker style="width: 200px;" v-model="queryParams.timeDate" type="daterange"
                            range-separator="至" start-placeholder="开始时间" end-placeholder="结束时间"
                            @change="handleTimeChange" format="YYYY-MM-DD" value-format="YYYY-MM-DD" />
                    </el-form-item>
                    <el-form-item label="订单类别：" prop="orderPrintStatus">
                        <el-select style="width: 100px;" v-model="queryParams.orderPrintStatus" clearable>
                            <el-option label="未打印" value="0"></el-option>
                            <el-option label="已打印" value="1"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="旺旺名称：" prop="workName">
                        <el-input style="width: 100px;" v-model="queryParams.workName" placeholder="请输入"></el-input>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
                        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
                    </el-form-item>
                </el-form>
            </template>
            <el-table v-loading="loading" :data="dataList">
                <el-table-column label="订单状态" prop="customizedName" align="center">
                    <template #default="scope">
                        <span v-if="scope.row == 1" style="color: #68C23D;">正常</span>
                        <span v-if="scope.row == 2" style="color: #E6A33F;">有逾期风险</span>
                        <span v-if="scope.row == 3" style="color: #F75F51;">已逾期</span>
                    </template>
                </el-table-column>
                <el-table-column label="制单日期" prop="customizedName" align="center">
                    <template #default="scope">
                        2024-12-20
                    </template>
                </el-table-column>
                <el-table-column label="交货日期" prop="updateTime" align="center">
                    <template #default="scope">
                        <span v-if="scope.row == 2" style="color: #E6A33F;">2024-12-20</span>
                        <span v-else-if="scope.row == 3" style="color: #F75F51;">2024-12-20</span>
                        <span v-else>2024-12-20</span>
                    </template>
                </el-table-column>
                <el-table-column label="组装用时详情" prop="customizedName" align="center">
                    <template #default="scope">
                        <el-button link type="primary" @click="goToDetails">查看详情</el-button>
                    </template>
                </el-table-column>
                <el-table-column label="客户名称" prop="customizedName" align="center">
                    <template #default="scope">
                        客户{{ scope.row }}
                    </template>
                </el-table-column>
                <el-table-column label="生产单号" prop="customizedName" align="center">
                    <template #default="scope">
                        <span style="color: #F75F51;">S240421001</span>
                    </template>
                </el-table-column>
                <el-table-column label="产品名称" prop="customizedName" align="center">
                    <template #default="scope">
                        XXXA款不锈钢(10人份)
                    </template>
                </el-table-column>
                <el-table-column label="订单数量" prop="customizedName" align="center">
                    <template #default="scope">
                        1000
                    </template>
                </el-table-column>
                <el-table-column label="半成品生产" prop="customizedName" align="center">
                    <template #default="scope">
                        <span v-if="scope.row == 1" style="color: #F75F51;">未开始</span>
                        <span v-if="scope.row == 2" style="color: #E6A33F;">进行中</span>
                        <span v-if="scope.row == 3" style="color: #68C23D;">已完成</span>
                    </template>
                </el-table-column>
                <el-table-column label="通用部件" prop="customizedName" align="center">
                    <template #default="scope">
                        <span v-if="scope.row == 1" style="color: #F75F51;">未开始</span>
                        <span v-if="scope.row == 2" style="color: #E6A33F;">进行中</span>
                        <span v-if="scope.row == 3" style="color: #68C23D;">已完成</span>
                    </template>
                </el-table-column>
                <el-table-column label="包装件" prop="customizedName" align="center">
                    <template #default="scope">
                        <span v-if="scope.row == 1" style="color: #F75F51;">未开始</span>
                        <span v-if="scope.row == 2" style="color: #E6A33F;">进行中</span>
                        <span v-if="scope.row == 3" style="color: #68C23D;">已完成</span>
                    </template>
                </el-table-column>
                <el-table-column label="成品组装" prop="customizedName" align="center">
                    <template #default="scope">
                        <span v-if="scope.row == 1" style="color: #F75F51;">未开始</span>
                        <span v-if="scope.row == 2" style="color: #E6A33F;">进行中</span>
                        <span v-if="scope.row == 3" style="color: #68C23D;">已完成</span>
                    </template>
                </el-table-column>
            </el-table>
            <pagination v-show="totalData > 0" :total="totalData" v-model:page="queryParams.pageNum"
                v-model:limit="queryParams.pageSize" @pagination="getList" />
        </el-card>
    </div>
</template>
<script setup lang="ts">
import { type FormInstance } from 'element-plus';

const { proxy } = getCurrentInstance() as any;
const queryFormRef = ref<FormInstance>();

const data = reactive<pageDataOnlyQuery<any>>({
    queryParams: {
        timeDate: '',
        startDate: '',
        endDate: '',
        pageSize: 10,
        pageNum: 1
    }
});

const { queryParams } = toRefs(data);

const loading = ref(false);
const dataList = ref<any>([]);
const totalData = ref(1);

const handleQuery = () => {
    queryParams.value.pageNum = 1;
    getList();
};

const resetQuery = () => {
    queryFormRef.value?.resetFields();
    queryParams.value.startDate = '';
    queryParams.value.endDate = '';
    queryParams.value.timeDate = '';
    handleQuery();
};

/** 日期选择 */
const handleTimeChange = (val: any) => {
    queryParams.value.startDate = val[0];
    queryParams.value.endDate = val[1];
};

const getList = async () => {
    dataList.value = [1, 2, 3]
};

const goToDetails = () => {
    proxy.$router.push({
        path: '/productionStatus/finishedProductAssemblyDetails'
    });
};

onMounted(() => {
    getList();
});

</script>
<style lang="scss" scoped>
.red {
    color: red;
}

.orange {
    color: orange;
}

.green {
    color: green;
}

.purple {
    color: #DF9BF9;
}
</style>